package ch11.d9;

public class MyThread extends Thread {
    boolean flag=false;//不暂停，运行
    static Object o=new Object();
    @Override
    public void run()  {

        for (int i = 1; ; i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            if(flag){
                flag=!flag;
                synchronized (o) {
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }




        }



    }
}
